	
	package servlet.title;
	
	import java.io.IOException;
	import javax.servlet.ServletException;
	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import service.TitleManager;
	import enitys.Title;
	
	public class UpdateTitle extends HttpServlet {
	
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
	
		/**
		 * Constructor of the object.
		 */
		public UpdateTitle() {
			super();
		}
		/**
		 * The doGet method of the servlet. <br>
		 *
		 * This method is called when a form has its tag value method equals to get.
		 * 
		 * @param request the request send by the client to the server
		 * @param response the response send by the server to the client
		 * @throws ServletException if an error occurred
		 * @throws IOException if an error occurred
		 */
		public void doGet(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			//创建表单Bean 封装数据
			Title form = new Title();
			form.setHead(request.getParameter("head"));
			form.setText(request.getParameter("text"));
			int id = Integer.parseInt(request.getParameter("id"));
			//获取业务对象  调用相应业务方法 修改通知方法
			TitleManager manager = TitleManager.getInstance();
			boolean flag = manager.modifyTitle(form,id);
			//根据返回的修改结果  向request中设置提示信息
			if(flag){
				request.setAttribute("message", "修改成功");
			}else{
				request.setAttribute("message", "修改失败");
			}
			//跳转页面
			this.getServletConfig().getServletContext().getRequestDispatcher("/servlet/TitleInfo").forward(request, response);
		}
	
		/**
		 * The doPost method of the servlet. <br>
		 *
		 * This method is called when a form has its tag value method equals to post.
		 * 
		 * @param request the request send by the client to the server
		 * @param response the response send by the server to the client
		 * @throws ServletException if an error occurred
		 * @throws IOException if an error occurred
		 */
		public void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
				doGet(request,response);
		}
	
		/**
		 * Initialization of the servlet. <br>
		 *
		 * @throws ServletException if an error occurs
		 */
		public void init() throws ServletException {
			// Put your code here
		}
	
	}
